<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="产品名称" prop="productName">
        <el-input
          v-model="queryParams.productName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="签约量" prop="signNum">
        <el-input
          v-model="queryParams.signNum"
          placeholder="请输入签约量/方"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="签约额" prop="signPrice">
        <el-input
          v-model="queryParams.signPrice"
          placeholder="请输入签约额/万元"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交付量" prop="deliverNum">
        <el-input
          v-model="queryParams.deliverNum"
          placeholder="请输入交付量/吨"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产值" prop="outputValue">
        <el-input
          v-model="queryParams.outputValue"
          placeholder="请输入产值/万元"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="应结算量" prop="settlementNum">-->
<!--        <el-input-->
<!--          v-model="queryParams.settlementNum"-->
<!--          placeholder="请输入应结算量/吨"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="应结算金额" prop="settlementPrice">-->
<!--        <el-input-->
<!--          v-model="queryParams.settlementPrice"-->
<!--          placeholder="请输入应结算金额/万元"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="应收金额" prop="amountReceivable">-->
<!--        <el-input-->
<!--          v-model="queryParams.amountReceivable"-->
<!--          placeholder="请输入应收金额/万元"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="收款金额" prop="amountCollected">
        <el-input
          v-model="queryParams.amountCollected"
          placeholder="请输入收款金额/万元"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="创建人姓名" prop="createByName">
        <el-input
          v-model="queryParams.createByName"
          placeholder="请输入创建人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客商名称" prop="tableTitle">
        <el-input
          v-model="queryParams.tableTitle"
          placeholder="请输入客商名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      <el-form-item label="创建人部门" prop="createByDept">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.createByDept"-->
      <!--          placeholder="请输入创建人部门"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item
        v-hasPermi="['data_upload:chem_product:list_all']"
        label="创建人部门" prop="createByDeptId">

        <el-select
          v-model="queryParams.createByDeptId"
          placeholder="请选择创建人部门"
          clearable
          @visible-change="getDepartments"
        >
          <el-option
            v-for="dept in deptList"
            :key="dept.deptId"
            :label="dept.deptName"
            :value="dept.deptId"
          ></el-option>
        </el-select>
      </el-form-item>
      <!--      <el-form-item label="创建人id" prop="createById">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.createById"-->
      <!--          placeholder="请输入创建人id"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item>
        <el-button
          v-hasPermi="['data_upload:chem_product:list_all','data_upload:chem_product:list','data_upload:chem_product:list_by_dept_id']"
          type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['data_upload:chem_product:add']"
        >新增</el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          type="success"-->
      <!--          plain-->
      <!--          icon="el-icon-edit"-->
      <!--          size="mini"-->
      <!--          :disabled="single"-->
      <!--          @click="handleUpdate"-->
      <!--          v-hasPermi="['data_upload:chem_product:edit']"-->
      <!--        >修改</el-button>-->
      <!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['data_upload:chem_product:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['data_upload:chem_product:export']"
        >导出</el-button>
        <el-button
          type="success"
          plain
          size="mini"
          @click="changeTable"
          v-hasPermi="['data_upload:chem_product:change']"
        >切换
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="chem_productList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--      <el-table-column label="id" align="center" prop="productId" />-->
      <el-table-column v-if="!isChange" label="产品名称" align="center" prop="productName" />
      <el-table-column v-if="!isChange" label="签约量/吨" align="center" prop="signNum" />
      <el-table-column v-if="!isChange" label="签约额/万元" align="center" prop="signPrice" />
      <el-table-column v-if="!isChange" label="交付量/吨" align="center" prop="deliverNum" />
      <el-table-column v-if="!isChange" label="产值/万元" align="center" prop="outputValue" />
<!--      <el-table-column v-if="!isChange" label="应结算量/吨" align="center" prop="settlementNum" />-->
<!--      <el-table-column v-if="!isChange" label="应结算金额/万元" align="center" prop="settlementPrice" />-->
<!--      <el-table-column v-if="!isChange" label="应收金额/万元" align="center" prop="amountReceivable" />-->
      <el-table-column v-if="!isChange" label="收款金额/万元" align="center" prop="amountCollected" />
      <el-table-column  label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建人姓名" align="center" prop="createByName" />
      <el-table-column label="创建人部门" align="center" prop="createByDept" />
      <el-table-column label="客商名称" align="center" prop="tableTitle"/>
      <!--      <el-table-column label="创建人部门id" align="center" prop="createByDeptId" />-->
      <!--      <el-table-column label="创建人id" align="center" prop="createById" />-->
      <el-table-column label="备注" align="center" prop="remark" />
      <!--      <el-table-column label="状态标志" align="center" prop="status" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-edit"-->
          <!--            @click="handleUpdate(scope.row)"-->
          <!--            v-hasPermi="['data_upload:chem_product:edit']"-->
          <!--          >修改</el-button>-->
          <!--          <el-button-->
          <!--            v-if="!isChange"-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-delete"-->
          <!--            @click="handleDelete(scope.row)"-->
          <!--            v-hasPermi="['data_upload:chem_product:remove']"-->
          <!--          >删除</el-button>-->
          <el-button
            v-if="isChange"
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="getOneBatchInfoByRemark(scope.row.remark)"
            v-hasPermi="['data_upload:chem_product:info']"
          >详情
          </el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改化学（产品）对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="881px" append-to-body>

      <div style="font-weight: bolder;width: 100%;font-size: 20px;text-align: center" >
          <span style="font-weight: bolder" >客商名称：&nbsp;
          </span>
        <el-input style="width: 200px" v-model="tableTitle" placeholder="以签订合同客商名称为准" />
      </div>
<br></br>
      <el-table
        style="width: 100%"
        :data="products"
        border
      >

        <br/>
        <el-table-column label="产品" prop="productName" width="140" align="center">
        </el-table-column>
        <el-table-column label="签约量/吨" prop="signNum" width="140" align="center">
          <template slot-scope="scope">
            <el-input style="width: 100%;height: 100%" v-model="scope.row.signNum"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="签约额/万元" prop="signPrice" width="140" align="center">
          <template slot-scope="scope">
            <el-input style="width: 100%;height: 100%" v-model="scope.row.signPrice"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="交付量/吨" prop="deliverNum" width="140" align="center">
          <template slot-scope="scope">
            <el-input style="width: 100%;height: 100%" v-model="scope.row.deliverNum"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="产值/万元" prop="outputValue" width="140" align="center">
          <template slot-scope="scope">
            <el-input style="width: 100%;height: 100%" v-model="scope.row.outputValue"></el-input>
          </template>
        </el-table-column>
<!--        <el-table-column label="应结算量/吨" prop="settlementNum" width="140" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <el-input style="width: 100%;height: 100%" v-model="scope.row.settlementNum"></el-input>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column label="应结算金额/万元" prop="settlementPrice" width="140" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <el-input style="width: 100%;height: 100%" v-model="scope.row.settlementPrice"></el-input>-->
<!--          </template>-->
<!--        </el-table-column>-->
<!--        <el-table-column label="应收金额/万元" prop="amountReceivable" width="140" align="center">-->
<!--          <template slot-scope="scope">-->
<!--            <el-input style="width: 100%;height: 100%" v-model="scope.row.amountReceivable"></el-input>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column label="收款金额/万元" prop="amountCollected" width="140" align="center">
          <template slot-scope="scope">
            <el-input style="width: 100%;height: 100%" v-model="scope.row.amountCollected"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="batchAdd" :disabled="isDisabled">确 定</el-button>
        <el-button @click="cancel" :disabled="isDisabled">取 消</el-button>
      </div>
    </el-dialog>


    <!--    详情展示-->
    <el-dialog :title="title" :visible.sync="oneBatchInfoOpen" append-to-body width="881px">
      <div v-if="oneBatchInfo.length!==0">
        <el-tag style="margin-right: 10px">{{ oneBatchInfo[0].createByName }}</el-tag>
        <el-tag style="margin-right: 10px">{{ oneBatchInfo[0].createByDept }}</el-tag>
        <el-tag style="margin-right: 10px">{{ parseTime(oneBatchInfo[0].createTime) }}</el-tag>
        <el-tag style="margin-right: 10px " >{{ oneBatchInfo[0].tableTitle}}</el-tag>
      </div>
      <br/>
      <el-table
        style="width: 100%"
        :data="oneBatchInfo"
        border
      >
        <el-table-column label="产品" prop="productName" width="140" align="center">
        </el-table-column>
        <el-table-column label="签约量/吨" prop="signNum" width="140" align="center">
        </el-table-column>
        <el-table-column label="签约额/万元" prop="signPrice" width="140" align="center">
        </el-table-column>
        <el-table-column label="交付量/吨" prop="deliverNum" width="140" align="center">
        </el-table-column>
        <el-table-column label="产值/万元" prop="outputValue" width="140" align="center">
        </el-table-column>
<!--        <el-table-column label="应结算量/吨" prop="settlementNum" width="140" align="center">-->
<!--        </el-table-column>-->
<!--        <el-table-column label="应结算金额/万元" prop="settlementPrice" width="140" align="center">-->
<!--        </el-table-column>-->
<!--        <el-table-column label="应收金额/万元" prop="amountReceivable" width="140" align="center">-->
<!--        </el-table-column>-->
        <el-table-column label="收款金额/万元" prop="amountCollected" width="140" align="center">
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeOneBatchInfo">关 闭</el-button>
      </div>

    </el-dialog>
  </div>
</template>

<script>
import { listChem_product, getChem_product, delChem_product, addChem_product, updateChem_product } from "@/api/data_upload/chem_product";
import { listDept } from '@/api/system/dept'
import { nanoid } from 'nanoid'

export default {
  name: "Chem_product",
  data() {
    return {
      tableTitle:null,
      isChange:true,
      oneBatchInfo:[],
      oneBatchInfoOpen:false,
      isDisabled: false,
      products: [
        {
          tableTitle:null,
          productId: null,
          productName: '外加剂',
          signNum: 0,
          signPrice: 0,
          deliverNum: 0,
          outputValue: 0,
          settlementNum: 0,
          settlementPrice: 0,
          amountReceivable: 0,
          amountCollected: 0,
          createTime: null,
          createByName: null,
          createByDept: null,
          createById: null,
          createByDeptId: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          status: null
        },
        {
          tableTitle:null,
          productId: null,
          productName: '混凝土纳米增强材料',
          signNum: 0,
          signPrice: 0,
          deliverNum: 0,
          outputValue: 0,
          settlementNum: 0,
          settlementPrice: 0,
          amountReceivable: 0,
          amountCollected: 0,
          createTime: null,
          createByName: null,
          createByDept: null,
          createById: null,
          createByDeptId: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          status: null
        },
        {
          tableTitle:null,
          productId: null,
          productName: '砂浆触变剂',
          signNum: 0,
          signPrice: 0,
          deliverNum: 0,
          outputValue: 0,
          settlementNum: 0,
          settlementPrice: 0,
          amountReceivable: 0,
          amountCollected: 0,
          createTime: null,
          createByName: null,
          createByDept: null,
          createById: null,
          createByDeptId: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          status: null
        },
        {
          tableTitle:null,
          productId: null,
          productName: '无碱液体速凝剂',
          signNum: 0,
          signPrice: 0,
          deliverNum: 0,
          outputValue: 0,
          settlementNum: 0,
          settlementPrice: 0,
          amountReceivable: 0,
          amountCollected: 0,
          createTime: null,
          createByName: null,
          createByDept: null,
          createById: null,
          createByDeptId: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          status: null
        },
        {
          tableTitle:null,
          productId: null,
          productName: '喷射混凝土降回弹材料',
          signNum: 0,
          signPrice: 0,
          deliverNum: 0,
          outputValue: 0,
          settlementNum: 0,
          settlementPrice: 0,
          amountReceivable: 0,
          amountCollected: 0,
          createTime: null,
          createByName: null,
          createByDept: null,
          createById: null,
          createByDeptId: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          status: null
        },
        {
          tableTitle:null,
          productId: null,
          productName: '其他(化学建材)',
          signNum: 0,
          signPrice: 0,
          deliverNum: 0,
          outputValue: 0,
          settlementNum: 0,
          settlementPrice: 0,
          amountReceivable: 0,
          amountCollected: 0,
          createTime: null,
          createByName: null,
          createByDept: null,
          createById: null,
          createByDeptId: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          status: null
        }
      ],
      deptList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 化学（产品）表格数据
      chem_productList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态标志时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        tableTitle:null,
        pageNum: 1,
        pageSize: 10,
        productName: null,
        signNum: null,
        signPrice: null,
        deliverNum: null,
        outputValue: null,
        settlementNum: null,
        settlementPrice: null,
        amountReceivable: null,
        amountCollected: null,
        createTime: null,
        createByName: null,
        createByDept: null,
        createByDeptId: null,
        createById: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },

  created() {
    this.getList();
  },
  methods: {
    changeTable() {
      //取反，isChange=true时表示已切换
      this.isChange = !this.isChange
      //切换时重置搜索栏
      this.resetQuery()
      //重新获取table数据，因为两种展示的数据不是一种格式
      this.getList()
    },
    closeOneBatchInfo() {

      this.oneBatchInfoOpen = false
      this.oneBatchInfo = []
    },
    getOneBatchInfoByRemark(remark) {
      getChem_product(remark).then(response => {

        this.oneBatchInfo = response.data
        this.oneBatchInfoOpen = true
      }).catch(() => {
        this.$modal.msgError('获取失败')
      })
    },
    resetProducts(){
      this.tableTitle=null,
      this.products=[
        {
          tableTitle:null,
          productId: null,
          productName: '外加剂',
          signNum: 0,
          signPrice: 0,
          deliverNum: 0,
          outputValue: 0,
          settlementNum: 0,
          settlementPrice: 0,
          amountReceivable: 0,
          amountCollected: 0,
          createTime: null,
          createByName: null,
          createByDept: null,
          createById: null,
          createByDeptId: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          status: null
        },
        {
          tableTitle:null,
          productId: null,
          productName: '混凝土纳米增强材料',
          signNum: 0,
          signPrice: 0,
          deliverNum: 0,
          outputValue: 0,
          settlementNum: 0,
          settlementPrice: 0,
          amountReceivable: 0,
          amountCollected: 0,
          createTime: null,
          createByName: null,
          createByDept: null,
          createById: null,
          createByDeptId: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          status: null
        },
        {
          tableTitle:null,
          productId: null,
          productName: '砂浆触变剂',
          signNum: 0,
          signPrice: 0,
          deliverNum: 0,
          outputValue: 0,
          settlementNum: 0,
          settlementPrice: 0,
          amountReceivable: 0,
          amountCollected: 0,
          createTime: null,
          createByName: null,
          createByDept: null,
          createById: null,
          createByDeptId: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          status: null
        },
        {
          tableTitle:null,
          productId: null,
          productName: '无碱液体速凝剂',
          signNum: 0,
          signPrice: 0,
          deliverNum: 0,
          outputValue: 0,
          settlementNum: 0,
          settlementPrice: 0,
          amountReceivable: 0,
          amountCollected: 0,
          createTime: null,
          createByName: null,
          createByDept: null,
          createById: null,
          createByDeptId: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          status: null
        },
        {
          tableTitle:null,
          productId: null,
          productName: '喷射混凝土降回弹材料',
          signNum: 0,
          signPrice: 0,
          deliverNum: 0,
          outputValue: 0,
          settlementNum: 0,
          settlementPrice: 0,
          amountReceivable: 0,
          amountCollected: 0,
          createTime: null,
          createByName: null,
          createByDept: null,
          createById: null,
          createByDeptId: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          status: null
        },
        {
          tableTitle:null,
          productId: null,
          productName: '其他(化学建材)',
          signNum: 0,
          signPrice: 0,
          deliverNum: 0,
          outputValue: 0,
          settlementNum: 0,
          settlementPrice: 0,
          amountReceivable: 0,
          amountCollected: 0,
          createTime: null,
          createByName: null,
          createByDept: null,
          createById: null,
          createByDeptId: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          status: null
        }
      ]
    },
    batchAdd() {
      this.$modal.msg('正在添加...')
      this.isDisabled = true
      new Promise((resolve, reject) => {
        let nanoId = nanoid()
        for (let i = 0; i < this.products.length-1; i++) {
          this.products[i].remark = nanoId
          this.products[i].tableTitle = this.tableTitle
          addChem_product(this.products[i])
        }
        this.products[this.products.length-1].remark = nanoId
        //加一下，记得
        this.products[this.products.length-1].tableTitle = this.tableTitle
        addChem_product(this.products[this.products.length-1]).then(()=>{
          this.getList()
        })
        resolve()
      }).then(() => {
        this.$modal.msgSuccess('新增成功')
        this.resetProducts()
        this.open = false
        this.isDisabled = false
      }).catch(() => {
        this.$modal.msgSuccess('新增失败')
        this.open = false
        this.isDisabled = false
      })

    },
    getDepartments() {
      if (this.deptList == null || this.deptList.length === 0) {
        listDept({}).then(response => {
          this.deptList = response.data
        })
      }
      return true
    },
    /** 查询化学（产品）列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      this.queryParams.isChange=this.isChange;
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listChem_product(this.queryParams).then(response => {
        this.chem_productList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        tableTitle:null,
        productId: null,
        productName: null,
        signNum: null,
        signPrice: null,
        deliverNum: null,
        outputValue: null,
        settlementNum: null,
        settlementPrice: null,
        amountReceivable: null,
        amountCollected: null,
        createTime: null,
        createByName: null,
        createByDept: null,
        createByDeptId: null,
        createById: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        status: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.productId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加化学（产品）";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const productId = row.productId || this.ids
      getChem_product(productId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改化学（产品）";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.productId != null) {
            updateChem_product(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addChem_product(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const productIds = row.productId || this.ids;
      this.$modal.confirm('是否确认删除化学（产品）编号为"' + productIds + '"的数据项？').then(function() {
        return delChem_product(productIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('data_upload/chem_product/export', {
        ...this.queryParams
      }, `chem_product_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
